import store from '@/store/index.js';
// const baseUrl = 'http://10.65.135.196:8860/clue/uniapp/' //测试
const baseUrl = 'https://workapp.sunfonda.com.cn:28149/clue/uniapp/' //正式





// const baseUrl = 'https://workapp.sunfonda.com.cn/erp/' 
// const baseUrl = 'https://workapp.sunfonda.com.cn:28148/ins/uniapp/' 
const request = (url = '', date = {}, type = 'GET', header = {
	'Content-Type': 'application/x-www-form-urlencoded',
	"Access-Control-Allow-Origin":"*",
	"userCode":store.state.userListName.userCode,
	"companyCode":store.state.userList.companyCode
	
}) => {
	return new Promise((resolve, reject) => {
		uni.request({
			method: type,
			url: baseUrl + url,
			data: date,
			header: header,
			dataType: 'json',
		}).then((response) => {
			let [error, res] = response;
			// console.log(response,"response")
			if (res.data) {
				// setTimeout(function() {
				// 	uni.reLaunch({
				// 		url: '/pages/sys/login/forget'
				// 	})
				// }, 2000);
				// uni.showToast({
				// 	title: '信息过期',
				// 	icon: 'error', //不要图标
				// 	duration: 2000 //1后消失
				// });


			}

			resolve(res.data);
		}).catch(error => {
			uni.hideLoading();
			uni.showToast({
				title: '请求错误,请联系管理员处理.',
				icon: 'none', //不要图标
				duration: 3000 //1后消失
			});
			let [err, res] = error;
			reject(err)

		})

	});
}
export default request
